package edu.usc.tweetool.hibernate;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * UserTheta entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see edu.usc.tweetool.hibernate.UserTheta
 * @author MyEclipse Persistence Tools
 */

public class UserThetaDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(UserThetaDAO.class);
	// property constants
	public static final String ART_DESIGN = "artDesign";
	public static final String BOOKS = "books";
	public static final String BUSINESS = "business";
	public static final String CHARITY = "charity";
	public static final String ENTERTAINMENT = "entertainment";
	public static final String FAMILY = "family";
	public static final String FASHION = "fashion";
	public static final String FOOD_DRINK = "foodDrink";
	public static final String HEALTH = "health";
	public static final String MUSIC = "music";
	public static final String NEWS = "news";
	public static final String SCIEN_TECH = "scienTech";
	public static final String SPORTS = "sports";

	protected void initDao() {
		// do nothing
	}

	public void save(UserTheta transientInstance) {
		log.debug("saving UserTheta instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(UserTheta persistentInstance) {
		log.debug("deleting UserTheta instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public UserTheta findById(java.lang.Long id) {
		log.debug("getting UserTheta instance with id: " + id);
		try {
			UserTheta instance = (UserTheta) getHibernateTemplate().get(
					"edu.usc.tweetool.hibernate.UserTheta", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(UserTheta instance) {
		log.debug("finding UserTheta instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding UserTheta instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from UserTheta as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByArtDesign(Object artDesign) {
		return findByProperty(ART_DESIGN, artDesign);
	}

	public List findByBooks(Object books) {
		return findByProperty(BOOKS, books);
	}

	public List findByBusiness(Object business) {
		return findByProperty(BUSINESS, business);
	}

	public List findByCharity(Object charity) {
		return findByProperty(CHARITY, charity);
	}

	public List findByEntertainment(Object entertainment) {
		return findByProperty(ENTERTAINMENT, entertainment);
	}

	public List findByFamily(Object family) {
		return findByProperty(FAMILY, family);
	}

	public List findByFashion(Object fashion) {
		return findByProperty(FASHION, fashion);
	}

	public List findByFoodDrink(Object foodDrink) {
		return findByProperty(FOOD_DRINK, foodDrink);
	}

	public List findByHealth(Object health) {
		return findByProperty(HEALTH, health);
	}

	public List findByMusic(Object music) {
		return findByProperty(MUSIC, music);
	}

	public List findByNews(Object news) {
		return findByProperty(NEWS, news);
	}

	public List findByScienTech(Object scienTech) {
		return findByProperty(SCIEN_TECH, scienTech);
	}

	public List findBySports(Object sports) {
		return findByProperty(SPORTS, sports);
	}

	public List findAll() {
		log.debug("finding all UserTheta instances");
		try {
			String queryString = "from UserTheta";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public UserTheta merge(UserTheta detachedInstance) {
		log.debug("merging UserTheta instance");
		try {
			UserTheta result = (UserTheta) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(UserTheta instance) {
		log.debug("attaching dirty UserTheta instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(UserTheta instance) {
		log.debug("attaching clean UserTheta instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static UserThetaDAO getFromApplicationContext(ApplicationContext ctx) {
		return (UserThetaDAO) ctx.getBean("UserThetaDAO");
	}
}